package com.doudou.dubbo.samples.frontend.service;

import com.doudou.dubbo.samples.detail.api.DetailService;
import com.doudou.dubbo.samples.detail.po.Item;
import com.doudou.dubbo.samples.frontent.api.ShopService;
import com.doudou.dubbo.samples.order.api.OrderService;
import com.doudou.dubbo.samples.order.po.Order;
import com.doudou.dubbo.samples.order.po.OrderDetail;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import om.doudou.dubbo.samples.user.api.UserService;
import om.doudou.dubbo.samples.user.po.User;

@Component
public class ShopServiceImpl implements ShopService {
    private static final Logger logger = LoggerFactory.getLogger(ShopServiceImpl.class);

    @DubboReference(check = false, retries = 0)
    private UserService userService;

    @DubboReference(check = false)
    private OrderService orderService;

    @DubboReference(check = false)
    private DetailService detailService;

    @Override
    public boolean register(String username, String password, String realName, String mail, String phone) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setRealName(realName);
        user.setMail(mail);
        user.setPhone(phone);
        return userService.register(user);
    }

    @Override
    public boolean login(String username, String password) {
        return userService.login(username, password) != null;
    }

    @Override
    public User getUserInfo(String username) {
        logger.info("getUserInfo username ----------------------------->>>> :{}", username);
        return userService.getInfo(username);
    }

    @Override
    public boolean timeoutLogin(String username, String password) {
        return userService.timeoutLogin(username, password) != null;
    }

    @Override
    public Item checkItem(long sku, String username) {
        return detailService.getItem(sku, username);
    }

    @Override
    public Item checkItemGray(long sku, String username) {
        return detailService.getItem(sku, username);
    }

    @Override
    public OrderDetail submitOrder(long sku, int count, String address, String phone, String receiver) {
        Order order = new Order();
        order.setSku(sku);
        order.setCount(count);
        order.setAddress(address);
        order.setPhone(phone);
        order.setReceiver(receiver);
        return orderService.submitOrder(order);
    }
}